package com.yonyou.pmclouds.alterandvisacategory.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.alterandvisacategory.entity.AlterAndVisaCategoryVO;
import com.yonyou.pmclouds.alterandvisacategory.rmiitf.AlterAndVisaCategoryMaintain;
import com.yonyou.pmclouds.alterandvisacategory.rmiitf.AlterAndVisaCategoryQuery;
import com.yonyou.pmclouds.basecom.entity.AdditionalPropertiesVOWrapper;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.basecom.service.CommonPropertiesProcessor;
import com.yonyou.pmclouds.outter.user.UserInfoQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 变更签证类别
 */
@RequestMapping("/alterandvisacategory")
@RestController
public class AlterAndVisaCategoryController {
    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private AlterAndVisaCategoryMaintain maintain;
    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private AlterAndVisaCategoryQuery categoryQuery;

    @Autowired
    private UserInfoQuery userQuery;
    @Autowired
    private CommonPropertiesProcessor propertiesProcessor;

    private static final String[] USER_ID_FIELDS = {"creator"};
    private static final String[] USER_NAME_FIELDS = {"creatorName"};

    /**
     * 提交
     */
    @RequestMapping(value = "/add")
    public AlterAndVisaCategoryVO add(@RequestBody AlterAndVisaCategoryVO alterAndVisaCategoryVO) throws BusinessException {
        if (alterAndVisaCategoryVO == null) return null;
        return maintain.insert(alterAndVisaCategoryVO);
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify")
    public AlterAndVisaCategoryVO modify(@RequestBody AlterAndVisaCategoryVO alterAndVisaCategoryVO) throws BusinessException {
        if (alterAndVisaCategoryVO == null) return null;
        return maintain.update(alterAndVisaCategoryVO);
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody AlterAndVisaCategoryVO alterAndVisaCategoryVO) throws BusinessException {
        if (alterAndVisaCategoryVO == null) return null;
        return maintain.delete(alterAndVisaCategoryVO.getPkAltervisacategory(), alterAndVisaCategoryVO.getChangeFlag());
    }

    /**
     * 获取变更签证分类列表
     */
    @RequestMapping(value = "/getList")
    public AlterAndVisaCategoryVO[] getList(@RequestParam(name = "isVisa") Byte isVisa) throws BusinessException {
        AlterAndVisaCategoryVO[] result = categoryQuery.queryCategoryListInfo(RuntimeEnvironment.getTenantId(), isVisa);
        userQuery.tranUserInfoField(result, USER_ID_FIELDS, USER_NAME_FIELDS);
        result = result == null ? new AlterAndVisaCategoryVO[0] : result;
        return result;
    }

}
